{layout name="main" /}
<section class="layui-larry-box">
    <div class="larry-personal">
        <blockquote class="layui-elem-quote mylog-info-tit">
            <ul class="layui-tab-title" style="border: 0">
                <a id="addMenu" class="layui-btn layui-btn-normal" ><i class="layui-icon">&#xe654;</i>添加菜单</a>
            </ul>
        </blockquote>
        <div class="larry-separate"></div>
        <div class="larry-personal-body clearfix mylog-info-box">
            <div class="layui-field-box layui-show">
                <div class="row">
                    <div class="col-md-12 col-lg-12 col-xs-12" style="min-height: 600px; display: inline-block;  border: 1px solid #ddd; overflow: auto;">
                        <ul id="node"></ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    var form;
    layui.use(['jquery','layer','form'],function(){
        form = layui.form;
        window.jQuery = window.$ = layui.jquery;
        window.layer = layui.layer;
        var url = '{:url("system/menu/getMenu")}';

        $.post(url,{},function (res) {
            layui.use('tree', function(){
                layui.tree({
                    elem: '#node'
                    ,nodes: res.data,
                    click:function (node) {
                        var id = node.id;
                        var url = "{:url('system/menu/edit')}?id=" + id;

                        openLayer(url,{
                            title:"编辑菜单",width:"600px",height:"600px",
                            btn:['保存','删除','取消']
                        },{
                            yes:function () {
                                submitForm('#system_menu_edit_form',done);
                            },btn2:function (index) {
                                url = "{:url('system/menu/delete')}?id=" + id;
                                postSomething(url,{},done);
                                layer.close(index);
                                return false;
                            },btn3:function (index) {
                                layer.close(index);
                            },success:function () {
                                form.render();
                            }
                        })
                    }
                });
            });
        });
    });

    function done(res) {
        if(res.code){
            layer.msg(res.msg,{icon:1,time:1500},function () {
                window.location.reload();
            });
        }else{
            layer.msg(res.msg,{icon:2,time:1500});
        }
    }

    $("#addMenu").click(function () {
        var url = "{:url('system/menu/add')}";

        openLayer(url,{
            title:"添加菜单",width:"600px",height:"600px",
            btn:['添加','取消']
        },{
            yes:function () {
                submitForm('#system_menu_add_form',done);
            },btn2:function (index) {
                layer.close(index);
                return false;
            },success:function () {
                form.render();
            }
        })
    });

</script>